package com.yuyou.activity.util.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImgUtils {

	
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
    /**
     * 获取网络图片流
     * 
     * @param url
     * @return
     * @throws Exception 
     * @throws MalformedURLException 
     */
    public InputStream getImageStream(String url) {
        try {
            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
            connection.setReadTimeout(5000);
            connection.setConnectTimeout(5000);
            connection.setRequestMethod("GET");
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream inputStream = connection.getInputStream();
                return inputStream;
            }
        } catch (IOException e) {
            logger.error("获取网络图片出现异常，图片路径为：",e);
        }
        return null;
    }
    
}
